package com.mtiiot.mq;

import com.mtiiot.mq.utils.Contants;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by xyr on 2016/9/20.
 */
public class BootStrap {
    private static Logger logger = LogManager.getLogger(BootStrap.class);
    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            String logPath=null;
            String aplicationPath=null;
            if(args!=null&&args.length>0){
                InputStream ins=null;
                try {
                    System.setProperty("configPath","file:"+args[0]);
                    Properties pps = new Properties();
                    ins=new FileInputStream(args[0]);
                    pps.load(ins);
                    logPath=pps.getProperty("fsmqservice.logConfigPath");
                    aplicationPath=pps.getProperty("fsmqservice.applicationPath");
                    Contants.FSTASK_HOST=pps.getProperty("fsmqservice.host");
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }finally {
                    if(ins!=null){
                        ins.close();
                    }
                }
            }else{
                System.out.println("Exception info:"+"input args error!! ");
                //logger.error("Exception info:"+"input args error!! ");
                return;
            }
            PropertyConfigurator.configure(logPath);

            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("file:"+aplicationPath);
            context.start();
            logger.info("定时任务应用启动成功...");
        } catch (Exception e) {
            logger.error("Exception trace:"+e.getMessage());
        }
    }
}
